﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Transactions;
using IssueTracker.Data;
using IssueTracker.Business.Entity;

namespace IssueTracker.Business.BO
{
    public class IssueWfHistoryBO
    {

  
        private IssueWfHistoryDataAccess da;

        public IssueWfHistoryBO() 
        {
            da = new IssueWfHistoryDataAccess();
        }


#region Business Methods

        /// <summary>
        /// Add a new IssueWfHistory
        /// </summary>
        /// <param name="IssueWfHistory"></param>
        /// <returns></returns>
        public IssueWfHistory AddNew(IssueWfHistory IssueWfHistory)
        {
            IssueWfHistory returnIssueWfHistory;

            IssueWfHistory.CreationDate = DateTime.Today.Date;

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    returnIssueWfHistory = da.Create(IssueWfHistory);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                
            }

            return returnIssueWfHistory;

        }

        public IssueWfHistory UpdateIssueWfHistory(IssueWfHistory IssueWfHistory)
        {
            IssueWfHistory returnIssueWfHistory;

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    returnIssueWfHistory = da.Update(IssueWfHistory);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                
                return returnIssueWfHistory;
            }
        }

        public void DeleteIssueWfHistory(IssueWfHistory IssueWfHistory)
        {
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    da.Delete(IssueWfHistory);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

        public IEnumerable<IssueWfHistory> ListIssueWfHistorys()
        {
            IssueWfHistoryDataAccess data = new IssueWfHistoryDataAccess();

            IEnumerable<IssueWfHistory> returnList = data.List();
            return returnList;
        }

        public IssueWfHistory GetIssueWfHistory(System.Guid id)
        {
            return da.Retrieve(id);
        }

        public IEnumerable<IssueWfHistory> ListIssueWfHistoriesByRef(System.Guid reference)
        {
            return da.ListByReferenceId(reference);
        }
        
#endregion
        
   
    }
}
